#include "Register_Window.h"


Register_Window::Register_Window(HINSTANCE p_instance)
{
	this->sm_instance=p_instance;
}
bool Register_Window::InitWindow()
{
	WNDCLASSEX m_wcex;
	m_wcex.cbSize = sizeof(WNDCLASSEX);
	m_wcex.style			= CS_HREDRAW | CS_VREDRAW;
	m_wcex.lpfnWndProc	= (WNDPROC)Winproc;
	m_wcex.cbClsExtra		= 0;
	m_wcex.cbWndExtra		= 0;
	m_wcex.hInstance		= sm_instance;
	m_wcex.hIcon			= 0;
	m_wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	m_wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	m_wcex.lpszMenuName	= NULL;
	m_wcex.lpszClassName	= NameClass;
	m_wcex.hIconSm		= 0;
	RegisterClassEx(&m_wcex);
	sm_handle = CreateWindow(NameClass, 
		NameClass, 
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 
		CW_USEDEFAULT, 
		SCREEN_WIDTH,   
 		SCREEN_HEIGHT, 
		NULL, 
		NULL, 
		sm_instance, 
		NULL);
	if (!sm_handle)
	{
		return false;
	}
	if (!SetWindowPos(sm_handle , HWND_NOTOPMOST , 200, 100 , SCREEN_WIDTH , SCREEN_HEIGHT , SWP_SHOWWINDOW))
	{
		return false;
	}
	bool _show = false;
	while (!_show)
	{
		_show = ShowWindow(sm_handle, SW_SHOW);
	}
	UpdateWindow(sm_handle);
	return true;
}
HWND Register_Window::GetHandle()
{
	return sm_handle;
}
HINSTANCE Register_Window::GetInstance()
{
	return sm_instance;
}
LRESULT CALLBACK Register_Window::Winproc(HWND p_handle,UINT p_message,WPARAM p_wparam,LPARAM p_lparam)
{
	switch (p_message) 
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc(p_handle, p_message, p_wparam, p_lparam);
}